@@ -1,51 +1,57 @@ |
||
1 |
-About WhoIz |
|
1 |
+J1X Whois API |
|
2 | 2 |
=========== |
3 | 3 |
|
4 |
-WhoIz is a simple WHOIS lookup application. It's built on Sinatra and Heroku friendly. |
|
4 |
+A simple WHOIS lookup API. |
|
5 | 5 |
|
6 |
+Based on the [Whoiz](https://github.com/okor/whoiz) by [Jason Ormand](http://jasonormand.com/2012/06/10/a-free-whois-api/) application and usging the [Ruby Whois](http://whoisrb.org/) gem. |
|
6 | 7 |
|
7 |
-Use It |
|
8 |
+How it works |
|
8 | 9 |
====== |
9 | 10 |
|
10 |
-JSON |
|
11 |
+Access the J1X Whois API and get a JSON response back. |
|
11 | 12 |
|
12 |
- curl http://whoiz.herokuapp.com/lookup.json?url=yahoo.com |
|
13 |
+Browser |
|
13 | 14 |
|
14 |
-Browser |
|
15 |
- |
|
16 |
- http://whoiz.herokuapp.com |
|
17 |
- http://whoiz.herokuapp.com/lookup?url=yahoo.com |
|
15 |
+ http://whois.j1x.co |
|
16 |
+ http://whois.j1x.co/lookup?url=google.com |
|
18 | 17 |
|
18 |
+curl |
|
19 | 19 |
|
20 |
-Clone It |
|
21 |
-======== |
|
22 |
- git clone git://github.com/okor/whoiz.git |
|
20 |
+ curl http://whois.j1x.co/lookup.json?url=google.com |
|
23 | 21 |
|
24 | 22 |
|
25 |
-Restrict It |
|
26 |
-=========== |
|
27 |
- |
|
28 |
-Edit |
|
23 |
+# Install |
|
29 | 24 |
|
30 |
- main.rb |
|
25 |
+### Clone |
|
31 | 26 |
|
32 |
-Change this |
|
27 |
+ git clone git://gitlab.j1x.co/j1x/whois-server.git |
|
33 | 28 |
|
34 |
- before do |
|
35 |
- response['Access-Control-Allow-Origin'] = '*' |
|
36 |
- end |
|
29 |
+### Restrict It |
|
37 | 30 |
|
38 |
-To this |
|
31 |
+Edit ```main.rb```: |
|
39 | 32 |
|
40 | 33 |
before do |
41 | 34 |
response['Access-Control-Allow-Origin'] = 'http://yourwebsite.com' |
42 | 35 |
end |
43 | 36 |
|
37 |
+Or use ```*``` to allow any website to access the API. |
|
38 |
+ |
|
39 |
+ |
|
40 |
+### Deploy It |
|
44 | 41 |
|
45 |
-Deploy It |
|
46 |
-========= |
|
47 | 42 |
heroku create |
48 | 43 |
git push heroku master |
49 | 44 |
heroku open |
50 | 45 |
|
46 |
+Development Resources |
|
47 |
+========= |
|
48 |
+ |
|
49 |
+### Tools |
|
50 |
+ |
|
51 |
+* [Rubular](http://rubular.com/) - a Ruby regular expression editor |
|
52 |
+ |
|
53 |
+### Articles |
|
51 | 54 |
|
55 |
+* [CORS with Angular.js and Sinatra](http://samurails.com/tutorial/cors-with-angular-js-and-sinatra/) |
|
56 |
+* [Introducing rack-cors](http://blog.sourcebender.com/2010/06/09/introducin-rack-cors.html) |
|
57 |
+* [Ruby Regular Expressions](http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm) |
@@ -31,7 +31,7 @@ class WhoisParser |
||
31 | 31 |
# Available? |
32 | 32 |
@parsed_data["available?"] = data["available?"] |
33 | 33 |
|
34 |
- if raw |
|
34 |
+ if raw || dev |
|
35 | 35 |
# Parsed whois lookup data |
36 | 36 |
#@parsed_data["whois_lookup"] = data |
37 | 37 |
# Raw whois lookup data |
@@ -36,12 +36,6 @@ end |
||
36 | 36 |
|
37 | 37 |
Whois::Server.define :tld, ".network", "whois.donuts.co" |
38 | 38 |
|
39 |
-before do |
|
40 |
- content_type :json |
|
41 |
- headers 'Access-Control-Allow-Origin' => '*', |
|
42 |
- 'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST'] |
|
43 |
-end |
|
44 |
- |
|
45 | 39 |
set :protection, false |
46 | 40 |
|
47 | 41 |
helpers do |
@@ -83,10 +77,20 @@ end |
||
83 | 77 |
get '/lookup.json' do |
84 | 78 |
content_type 'application/json' |
85 | 79 |
response["Content-Type"] = "application/json" |
80 |
+ headers 'Access-Control-Allow-Origin' => '*', |
|
81 |
+ 'Access-Control-Allow-Methods' => ['OPTIONS', 'GET', 'POST'] |
|
86 | 82 |
begin |
87 | 83 |
#cache_for_day |
88 | 84 |
parser = WhoisParser.new |
89 |
- data = whois_lookup.to_h |
|
85 |
+ if whois_lookup.class != Array |
|
86 |
+ data = whois_lookup.to_h |
|
87 |
+ else |
|
88 |
+ if whois_lookup.first.class != Array |
|
89 |
+ data = whois_lookup.first.to_h |
|
90 |
+ else |
|
91 |
+ data = "" |
|
92 |
+ end |
|
93 |
+ end |
|
90 | 94 |
parser.parse(data, whois_lookup, params[:url], params[:raw], params[:dev]) |
91 | 95 |
rescue Exception => e |
92 | 96 |
@error = e |